package servlet;

import bean.BookBean;
import service.IBookService;
import service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "ShowServlet",value = "/show")
public class ShowServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
         response.setContentType("text/html;charset=utf-8");
        IBookService iBookService = new BookServiceImpl();
        List<BookBean> list = iBookService.showAllBooksInfo();
        //显示所有图书的信息
        PrintWriter out = response.getWriter();

        HttpSession session = request.getSession();

        session.setAttribute("books",list);

         response.sendRedirect("jsp/show.jsp");


/*
        out.print("<html>");
        out.print("<body>");
        out.print("<table border='1'>");
        out.print("<tr><td>图片</td><td>书名</td><td>价格</td><td>操作</td></tr>");
        for (BookBean bookBean : list) {
            out.print("<tr><td><img style='width:50px;height:80px' src='javaImg/"+bookBean.getPic()+"'/></td><td>"+bookBean.getName()+"</td><td>"+bookBean.getPrice()+"</td><td><a href='shop?bookId="+bookBean.getId()+"'>购买</a></td></tr>");
        }
        out.print("</table>");
        out.print("</body>");
        out.print("</html>");*/



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     doPost(request,response);
    }
}
